package com.sikaryofficial.backend.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * @author : qinjinyuan
 * @desc : 工单状态
 * @date : 2023/11/04 10:08
 */
@Getter
@AllArgsConstructor
public enum WorkOrderStatusEnum {
    /**
     * 1-待处理
     */
    ACCEPTING(1, "Accepting"),
    /**
     * 2-处理中
     */
    ACCEPTED(2, "Accepted");

    private final Integer code;
    private final String name;

    public static WorkOrderStatusEnum getByCode(Integer code) {
        return Arrays.stream(WorkOrderStatusEnum.values())
                .filter(enumCode -> Objects.nonNull(code) && enumCode.getCode().equals(code))
                .findFirst().orElse(null);
    }

    public static String getDescByCode(Integer code) {
        return Optional.ofNullable(getByCode(code)).map(WorkOrderStatusEnum::getName).orElse(null);
    }
}
